<?php
namespace app\index\controller;
use think\Controller;
use think\Db;
use think\Session;
class LiveUser extends Controller{
    /****
     Class register           个人中心头部
     *@
    */
    public function head(){
        $user_id = input('user_id');
        $user = Db::name('user')
            ->where(['id'=>$user_id])
            ->find();
        $attention = Db::name('attention')
                  ->where(['user_id'=>$user_id])
                  ->count();
        $attention_user_id = Db::name('attention')
                  ->where(['attention_user_id'=>$user_id])
                  ->count();
        $headline_consult = Db::name('headline_consult')
                  ->where(['user_id'=>$user_id])
                  ->count();
        if($user){ 
           $arr = [
               'state'              => 1,
               'attention'          =>$attention,
               'attention_user_id'  =>$attention_user_id,
               'headline_consult'   =>$headline_consult,
               'user'               =>$user,
               'message'            => "请求成功"
            ]; 
        }else{
            $arr = [
               'state'     => 0,
               'session'  =>$user_id,
               'message'   => "用户不存在"
            ]; 
        }
        return json($arr);
    }


    /****
     Class register         关注
     *@
    */
    
    public function attention(){
      $post = input('post.');
      $data = [
        'attention_user_id'=>$post['attention_user_id'],
        'user_id'=>$post['user_id'],
      ];
      $attention = Db::name('attention')->insert($data);
      if($attention){
         $arr = [
             'state'     => 1,
             'message'   => "请求成功"
          ]; 
      }else{
        $arr = [
             'state'     => 0,
             'message'   => "请求失败"
          ];
      }
      return json($arr);

    }
	
	
	 public function placard(){
      $user_id = input('user_id');
      $placard = Db::name('placard')->where(['user_id'=>$user_id])->find();
      if($attention){
         $arr = [
             'state'     => 1,
             'placard'   =>$placard,
             'message'   => "请求成功"
          ]; 
      }else{
        $arr = [
             'state'     => 0,
             'placard'   =>'',
             'message'   => "空"
          ];
      }
      return json($arr);

    }
    public function placard_add(){
      $user_id = input('post.');
      $placard = Db::name('placard')->where(['user_id'=>$user_id])->find();
       $data = [
          'user_id'=>$user_id,
          'content'=>$post['content']
      ];
      if($placard){
           $placard = Db::name('placard')
                    ->where(['user_id'=>$user_id])
                    ->insert($data);
          if($attention){
             $arr = [
                 'state'     => 1,
                 'message'   => "请求成功"
              ]; 
          }else{
            $arr = [
                 'state'     => 0,
                 'message'   => "空"
              ];
          }
          return json($arr);
      }else{
          $placard = Db::name('placard')
                    ->where(['user_id'=>$user_id])
                    ->update($data);
          if($attention){
             $arr = [
                 'state'     => 1,
                 'message'   => "请求成功"
              ]; 
          }else{
            $arr = [
                 'state'     => 0,
                 'message'   => "空"
              ];
          }
          return json($arr);
      }
      
    }
}